const path = require('path');
const webpack = require('webpack');
var PurifyCSS = require('purifycss-webpack');
var globAll = require('glob-all');
const ExtractTextWebpackPlugin = require('extract-text-webpack-plugin');
module.exports = {
  entry: {
    app: './src/app.js'
  },
  output: {
    path: path.resolve(__dirname, 'dist'),
    publicPath: './dist/',
    filename: '[name].bundle.js',
    chunkFilename: '[name].chunk.js'
  },
  module: {
    rules: [{
      test: /\.less$/,
      use: ExtractTextWebpackPlugin.extract({
        fallback: {
          loader: 'style-loader',
          options: {
            singleton: true,
            transform: './css.transform.js'
          }
        },
        use: [{
          loader: 'css-loader',
          options: {
            // minimize: true,
            // localIdentName: '[path][name]_[local]_[hash:base64:5]',
            // modules: true
          }
          // loader: 'file-loader'
        }, {
          loader: 'postcss-loader',
          options: {
            ident: 'postcss',
            plugins: [
              // require('autoprefixer')(),
              require('postcss-cssnext')()
            ]
          }
        }, {
          loader: 'less-loader'
        }]
      })
    },{
      test: /\.js$/,
      use: [
        {
          loader: 'babel-loader',
          options: {
            presets: ['env'],
            plugins: ['lodash'] 
          }
        }
      ]
    }]
  },
  plugins: [
    new ExtractTextWebpackPlugin({
      filename: '[name].min.css',
      allChunks: false // 给css提取一个范围
    }),
    new PurifyCSS({
      paths: globAll.sync([
        path.join(__dirname, './*.html'),
        path.join(__dirname, './src/*.js')
      ]) 
    }),
    new webpack.optimize.UglifyJsPlugin()
  ]
}